# Contributor: August Klein <amatcoder@gmail.com>
# Maintainer: August Klein <amatcoder@gmail.com>
pkgname=sdl2
pkgver=2.0.12
pkgrel=3
pkgdesc="development library designed to provide low level access to audio, keyboard, mouse, joystick and graphics"
url="https://www.libsdl.org"
arch="all"
license="Zlib"
depends_dev="directfb-dev mesa-dev"
makedepends="cmake alsa-lib-dev libxcursor-dev libxrandr-dev libxrender-dev
	libxscrnsaver-dev libxi-dev libx11-dev libxext-dev libusb-dev libxkbcommon-dev
	pulseaudio-dev wayland-dev wayland-protocols $depends_dev"
subpackages="$pkgname-dev"
source="https://www.libsdl.org/release/SDL2-$pkgver.tar.gz
	directfb-cflags.patch
	khronos.patch
	0001-src-video-directfb-SDL_DirectFB_render.c-fix-build.patch
	"
options="!check" # No good way to run the available tests
builddir="$srcdir/SDL2-$pkgver"

# secfixes:
#   2.0.10-r0:
#     - CVE-2019-7572
#     - CVE-2019-7573
#     - CVE-2019-7574
#     - CVE-2019-7575
#     - CVE-2019-7576
#     - CVE-2019-7578
#     - CVE-2019-7635
#     - CVE-2019-7636
#     - CVE-2019-7637
#     - CVE-2019-7638

build() {
	# NOTE: Please do not remove the -DVIDEO_DIRECTFB=ON flag.
	# Some apps, used for booting Alpine derivatives, require this to function!
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=True \
		-DSDL_TEST=OFF \
		-DALSA=ON \
		-DCLOCK_GETTIME=ON \
		-DARTS=OFF \
		-DESD=OFF \
		-DNAS=OFF \
		-DRPATH=OFF \
		-DVIDEO_X11=ON \
		-DVIDEO_DIRECTFB=ON \
		-DVIDEO_WAYLAND=ON \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DSDL_STATIC=ON \
		-DSDL_SHARED=ON \
		-DPULSEAUDIO_SHARED=ON \
		"$CMAKE_CROSSOPTS"
	make -C build
}

package() {
	make -C build DESTDIR="$pkgdir" install
}

sha512sums="3f1f04af0f3d9dda9c84a2e9274ae8d83ea0da3fc367970a820036cc4dc1dbf990cfc37e4975ae05f0b45a4ffa739c6c19e470c00bf3f2bce9b8b63717b8b317  SDL2-2.0.12.tar.gz
8efdd02e0e71908b913f4c05b1f02aa94315c2bbffff87d1a46db94723dd7f0ea177e1e00de6c212ad31a00a22aa0fd87f63c3865c4dff2dc98f302046084caf  directfb-cflags.patch
76c93659a122def05f341ba30507b546b201c84823236ca731ac801f092e769574e8f051770a76050a77ac846ed851abab604e0a6d578b382f4792ab47aa60ed  khronos.patch
8de7a7ea80eda5797adf29aa8123511f41dd6980e93203dfd2b080d915fa3b548e2712c68ff76ff09ef4b9cdbdc941cb728d01dc90c962b6bf6b96374de4aa8f  0001-src-video-directfb-SDL_DirectFB_render.c-fix-build.patch"
